"""
Copyright © 2024 Walkline Wang (https://walkline.wang)
Gitee: https://gitee.com/walkline/micropython-ws2812-digital-effect
"""
class Config(object):
	IN = 0
	OUT = 1

	DIGITALS_1 = {
		0: {
			IN: {
				# 0 in
				0: 0b001000000000100,
				1: 0b011100000001110,
				2: 0b111110000011111,
				3: 0b111111000111111,
			},
			OUT: {
				# 0 out
				0: 0b111110000011111,
				1: 0b011100000001110,
				2: 0b001000000000100,
				3: 0b000000000000000,
			},
		},
		1: {
			IN: {
				# 1 in
				0: 0b000000010000000,
				1: 0b000000111000000,
				2: 0b000001111100000,
				3: 0b100011111100001,
			},
			OUT: {
				# 1 out
				0: 0b000001111100000,
				1: 0b000000111000000,
				2: 0b000000010000000,
				3: 0x000000000000000,
			},
		},
		2: {
			IN: {
				# 2 in
				0: 0b000000010000000,
				1: 0b001000010000100,
				2: 0b001100010001100,
				3: 0b001110010011100,
				4: 0b001111010111100,
				5: 0b101111010111101,
			},
			OUT: {
				# 2 out
				0: 0b001111010111100,
				1: 0b001110010011100,
				2: 0b001100010001100,
				3: 0b001000010000100,
				4: 0b000000010000000,
				5: 0b000000000000000,
			},
		},
		3: {
			IN: {
				# 3 in
				0: 0b000000010000000,
				1: 0b001000010000100,
				2: 0b001000010001110,
				3: 0b001000010011111,
				4: 0b001001010111111,
				5: 0b101011010111111,
			},
			OUT: {
				# 3 out
				0: 0b001001010111111,
				1: 0b001000010011111,
				2: 0b001000010001110,
				3: 0b001000010000100,
				4: 0b000000010000000,
				5: 0b000000000000000,
			},
		},
		4: {
			IN: {
				# 4 in
				0: 0b000000010000000,
				1: 0b001000010000100,
				2: 0b011000010001110,
				3: 0b111000010011111,
			},
			OUT: {
				# 4 out
				0: 0b011000010001110,
				1: 0b001000010000100,
				2: 0b000000010000000,
				3: 0b000000000000000,
			},
		},
		5: {
			IN: {
				# 5 in
				0: 0b000000010000000,
				1: 0b001000010000100,
				2: 0b011000010000110,
				3: 0b111000010000111,
				4: 0b111001010100111,
				5: 0b111011010110111,
			},
			OUT: {
				# 5 out
				0: 0b111001010100111,
				1: 0b111000010000111,
				2: 0b011000010000110,
				3: 0b001000010000100,
				4: 0b000000010000000,
				5: 0b000000000000000,
			},
		},
		6: {
			IN: {
				# 6 in
				0: 0b000000010000000,
				1: 0b001000010000100,
				2: 0b011100010000110,
				3: 0b111110010000111,
				4: 0b111111010100111,
				5: 0b111111010110111,
			},
			OUT: {
				# 6 out
				0: 0b111111010100111,
				1: 0b111110010000111,
				2: 0b011100010000110,
				3: 0b001000010000100,
				4: 0b000000010000000,
				5: 0b000000000000000,
			},
		},
		7: {
			IN: {
				# 7 in
				0: 0b000000000000100,
				1: 0b000000000001110,
				2: 0b000000000011111,
				3: 0b000001000011111,
				4: 0b100001000011111,
			},
			OUT: {
				# 7 out
				0: 0b000001000011111,
				1: 0b000000000011111,
				2: 0b000000000001110,
				3: 0b000000000000100,
				4: 0b000000000000000,
			},
		},
		8: {
			IN: {
				# 8 in
				0: 0b000000010000000,
				1: 0b001000010000100,
				2: 0b011100010001110,
				3: 0b111110010011111,
				4: 0b111111010111111,
			},
			OUT: {
				# 8 out
				0: 0b111110010011111,
				1: 0b011100010001110,
				2: 0b001000010000100,
				3: 0b000000010000000,
				4: 0b000000000000000,
			},
		},
		9: {
			IN: {
				# 9 in
				0: 0b000000010000000,
				1: 0b001000010000100,
				2: 0b011000010001110,
				3: 0b111000010011111,
				4: 0b111001010111111,
				5: 0b111011010111111,
			},
			OUT: {
				# 9 out
				0: 0b111001010111111,
				1: 0b111000010011111,
				2: 0b011000010001110,
				3: 0b001000010000100,
				4: 0b000000010000000,
				5: 0b000000000000000,
			},
		},
	}

	DIGITALS_2 = {
		0: {
			IN : {
				0: 0b11111,
				1: 0b1111110001,
				2: 0b111111000111111,
			},
			OUT: {
				0: 0b100011111100000,
				1: 0b1111100000,
				2: 0b00000,
			},
		},
		1: {
			IN : {
				0: 0b10001,
				1: 0b1000111111,
				2: 0b100011111100001,
			},
			OUT: {
				0: 0b111110000100000, # 0
				1: 0b0000100000,      # 1, OUT1 + IN0
				2: 0b00000,           # 2, OUT2 + IN1
			},
		},
		2: {
			IN : {
				0: 0b10111,           # 0, OUT1 + IN0
				1: 0b1011110101,      # 1, OUT2 + IN1
				2: 0b101111010111101, # 2
			},
			OUT: {
				0: 0b101011110100000,
				1: 0b1110100000,
				2: 0b00000,
			},
		},
		3: {
			IN : {
				0: 0b10101,
				1: 0b1010110101,
				2: 0b101011010111111,
			},
			OUT: {
				0: 0b101011111100000,
				1: 0b1111100000,
				2: 0b00000,
			},
		},
		4: {
			IN : {
				0: 0b11100,
				1: 0b1110000100,
				2: 0b111000010011111,
			},
			OUT: {
				0: 0b001001111100000,
				1: 0b1111100000,
				2: 0b00000,
			},
		},
		5: {
			IN : {
				0: 0b11101,
				1: 0b1110110101,
				2: 0b111011010110111,
			},
			OUT: {
				0: 0b101011011100000,
				1: 0b1011100000,
				2: 0b00000,
			},
		},
		6: {
			IN : {
				0: 0b11111,
				1: 0b1111110101,
				2: 0b111111010110111,
			},
			OUT: {
				0: 0b101011011100000,
				1: 0b1011100000,
				2: 0b00000,
			},
		},
		7: {
			IN : {
				0: 0b10000,
				1: 0b1000010000,
				2: 0b100001000011111,
			},
			OUT: {
				0: 0b100001111100000,
				1: 0b1111100000,
				2: 0b00000,
			},
		},
		8: {
			IN : {
				0: 0b11111,
				1: 0b1111110101,
				2: 0b111111010111111,
			},
			OUT: {
				0: 0b101011111100000,
				1: 0b1111100000,
				2: 0b00000,
			},
		},
		9: {
			IN : {
				0: 0b11101,
				1: 0b1110110101,
				2: 0b111011010111111,
			},
			OUT: {
				0: 0b101011111100000,
				1: 0b1111100000,
				2: 0b00000,
			},
		},
	}


def convert_digitals_1():
	print('    DIGITALS_1 = {')

	for key, value in Config.DIGITALS_1.items():
		print('        %d: {' % key)
		print('            IN : (', end='')

		for key2, value2 in value[Config.IN].items():
			print('0x%04x, ' % value2, end='')

		print('),')
		print('            OUT: (', end='')

		for key2, value2 in value[Config.OUT].items():
			print('0x%04x, ' % value2, end='')

		print('),')
		print('        },')

	print('    }')

def convert_digitals_2():
	print('    DIGITALS_2 = {')

	for key, value in Config.DIGITALS_2.items():
		print('        %d: {' % key)
		print('            IN : (', end='')

		for key2, value2 in value[Config.IN].items():
			print('0x%04x, ' % value2, end='')

		print('),')
		print('            OUT: (', end='')

		for key2, value2 in value[Config.OUT].items():
			print('0x%04x, ' % value2, end='')

		print('),')
		print('        },')

	print('    }')


if __name__ == '__main__':
	convert_digitals_1()
	convert_digitals_2()
